﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.SqlServer.Types;

namespace StorageUnitTests
{
    using Storage.EntityModels;
    using Storage;

    #region TestsHelper

    /// <summary>
    /// Supports Unit Testing providing helper methods.
    /// </summary>
    public static class TestsHelper
    {
        #region Public static methods

        #region CleanUpDB

        /// <summary>
        /// Clean up the database.
        /// </summary>
        public static void CleanUpDB(TripLoaDataContext db)
        {
            #if TEST

            Process p = Process.Start(Environment.CurrentDirectory + @"\..\..\..\..\Build\clean_db.bat");
            p.WaitForExit();
            
            #endif
        } 

        #endregion

        #region CreateTripForSearch

        public static Trip CreateTripForSearch()
        {
        //User owner = new User()
        //    {
        //        Username = "romiera",
        //        City = "Follonica",
        //        Gender = Gender.Female,
        //        Name = "Romina",
        //        Birthday = new DateTime(1983, 11, 25),
        //        BookedIn = true,
        //        DrivingLicence = true,
        //        Smoker = Smoker.Smoker,
        //        Surname = "Paradisi",
        //        Address = "Via Europa",
        //        PhoneNumber = "12345678"
        //    };

        //    StorageManager.Instance.Entities.Users.InsertOnSubmit(owner);
        //    StorageManager.Instance.Entities.SubmitChanges();

        //    Trip tt = new Trip
        //    {
        //        AcceptSmoker = true,
        //        Accomplished = true,
        //        DepartureDate = new DateTime(2008, 5, 5),
        //        DeviationRadius = 10,
        //        Draft = false,
        //        EstimatedBudget = 30,
        //        EstimatedTime = 3,
        //        FreeSeats = 2,
        //        Owner = owner,
        //        RequireLicenced = true,
        //        ReservationExpirationDate = new DateTime(2008, 5, 4)
        //    };

        //    StorageManager.Instance.Entities.Trips.InsertOnSubmit(tt);
        //    StorageManager.Instance.Entities.SubmitChanges();

        //    Stage s = new Stage
        //    {
        //        Ordinal = 1,
        //        Origin = new Place()
        //        {
        //            MapPoint = SqlGeography.Point(89, 35, 4326)
        //        },
        //        Destination = new Place()
        //        {
        //            MapPoint = SqlGeography.Point(55, 55, 4326)
        //        },
        //        ReservedSeats = 2,
        //        BusySeats = 1,
        //        EstimatedTime = 200,
        //        EstimatedBudget = 1000,
        //        Users_VehicleDetails = new Users_VehicleDetails()
        //        {
        //            VehicleDetails = new VehicleDetails()
        //            {
        //                VehicleClass = VehicleTypes.Car,
        //                Model = "bel modello",
        //            },
        //            User = owner
        //        }
        //    };

        //    s.SetPath("(89 35), (55 55)");
        //    tt.Stages.Add(s);

        //    Stage s1 = new Stage
        //    {
        //        Ordinal = 2,
        //        Origin = new Place()
        //        {
        //            MapPoint = SqlGeography.Point(55, 55, 4326)
        //        },
        //        Destination = new Place()
        //        {
        //            MapPoint = SqlGeography.Point(41, 5, 4326)
        //        },
        //        ReservedSeats = 2,
        //        BusySeats = 1,
        //        EstimatedTime = 200,
        //        EstimatedBudget = 1000,
        //        Users_VehicleDetails = new Users_VehicleDetails()
        //        {
        //            VehicleDetails = new VehicleDetails()
        //            {
        //                VehicleClass = VehicleTypes.Car,
        //                Model = "bel modello",
        //            },
        //            User = owner
        //        }
        //    };
        //    s1.SetPath("(55 55), (41 5)");
        //    tt.Stages.Add(s1);

        //    StorageManager.Instance.Entities.SubmitChanges();

        //    return tt;

        return null;
    }

        #endregion

        #region CreateUser

        /// <summary>
        /// Creates a default user.
        /// </summary>
        /// <returns></returns>
        public static User CreateUser()
        {
            User result = new User
            {
                Username = "romiera",
                City = "Follonica",
                Gender = Gender.Female,
                Name = "Romina",
                Birthday = new DateTime(1983, 11, 25),
                BookedIn = true,
                DrivingLicence = true,
                Smoker = Smoker.NotSmoker,
                Surname = "Paradisi",
                Address = "Via Europa",
                PhoneNumber = "12345678",
            };
            return result;
        } 

        #endregion

        #region CreateDraftTrip

        /// <summary>
        /// Creates an empty (draft) trip.
        /// </summary>
        /// <returns></returns>
        public static Trip CreateDraftTrip()
        {
            Trip result = new Trip
            {
                Draft = true,
                Accomplished = false
            };

            return result;
        }

        #endregion

        #region CreateDrivingInfo

        /// <summary>
        /// Creates a default DrivingInfo.
        /// </summary>
        /// <returns></returns>
        public static DrivingInfo CreateDrivingInfo(int stageID, string info, SqlGeography mapPoint)
        {
            DrivingInfo result = new DrivingInfo
            {
                StageId = stageID,
                Info = info,
                MapPoint = mapPoint
            };
            return result;
        }

        #endregion 

        #region CreatePlace, CreatePlaceA, CreatePlaceB

        /// <summary>
        /// Creates a default Place.
        /// </summary>
        /// <returns></returns>
        public static Place CreatePlace(string city, string province, string state, string category,
            SqlGeography mapPoint)
        {
            Place result = new Place
            {
                City = city,
                Province = province,
                State = state,
                Category = category,
                MapPoint = mapPoint
            };
            return result;
        }

        /// <summary>
        /// Creates a default Place.
        /// </summary>
        /// <returns></returns>
        public static Place CreatePlaceA()
        {
            Place result = new Place
            {
                City = "sarzana",
                Province = "SP", 
                State = "ITA",
                Category = "svago",
                MapPoint = SqlGeography.Point(1, 2, 4326)
            };
            return result;
        }

        /// <summary>
        /// Creates a default Place.
        /// </summary>
        /// <returns></returns>
        public static Place CreatePlaceB()
        {
            Place result = new Place
            {
                City = "la spezia",
                Province = "SP",
                State = "ITA",
                Category = "svago",
                MapPoint = SqlGeography.Point(7, 8, 4326)
            };
            return result;
        }

        #endregion

        #region CreateStage

        /// <summary>
        /// Creates a default Stage.
        /// </summary>
        /// <returns></returns>
        public static Stage CreateStage()
        {
            //Stage result = new Stage
            //{
            //    Trip = CreateDraftTrip(),
            //    Ordinal = 1,
            //    Origin = CreatePlaceA(),
            //    Destination = CreatePlaceB(),
            //    ReservedSeats = 2,
            //    BusySeats = 1,
            //    EstimatedTime = 200,
            //    EstimatedBudget = 1000,
            //};
            
            //// FIX: need to be a path composed by Origin and Destination point.
            //result.SetPath("(1 2), (3 4), (5 6), (7 8)");

            //return result;
            return null;
        }

        #endregion

        #endregion
    }

    #endregion
}
